import axios from 'axios'
import {Assert} from "../common/Assert";

export const SubBiddingHistoryService = class SubBiddingHistoryService {
    static subBiddingHistoryService = null
    requestUrl = 'http://localhost/subBiddingHistorys'

    static getInstance() {
        if (this.subBiddingHistoryService == null) {
            this.subBiddingHistoryService = new SubBiddingHistoryService()
        }
        return this.subBiddingHistoryService
    }

    /**
     * 保存的方法
     * @param subBiddingHistory
     */
    save(subBiddingHistory) {
        return axios.post(this.requestUrl, subBiddingHistory)
    }

    /**
     * 撤销的方法
     * @param row
     */
    cancel(row) {
        row.status = '5'
        return axios.put(`${this.requestUrl}/operation`,row)
    }

    /**
     * 验证是否存在
     * @param subId
     */
    exist(subId) {
        return axios.get(`${this.requestUrl}/exist/${subId}`)
    }

    /**
     * 修改的方法
     * @param subBiddingHistory
     */
    update(subBiddingHistory) {
        return axios.put(this.requestUrl,subBiddingHistory)
    }

    /**
     * 分页查询
     * @param params
     */
    getPageList(params) {
        return axios.get(`${this.requestUrl}/page`,{
            params
        })
    }

    /**
     * 批量开标
     * @param ids
     */
    batchOpen(ids){
        return axios.put(`${this.requestUrl}/open/${ids}`,)
    }

    /**
     * 开标的方法
     * @param row
     */
    open(row){
        row.status = '2'
        return axios.put(`${this.requestUrl}/operation`,row)
    }

    /**
     * 选择合作
     * @param row
     */
    cooperation(row){
        row.status = '3'
        return axios.put(`${this.requestUrl}/cooperation`,row)
    }

    /**
     * 校验的方法
     * @param subBiddingHistory
     */
    check(subBiddingHistory){
        return !(!Assert.isNotNull(subBiddingHistory.offer, '请填写报价') || !Assert.isLessZero(subBiddingHistory.offer, '请填写合理的报价'));
    }
}
